package com.profiloc.ui.screens;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.VerticalFieldManager;

import com.profiloc.ui.custom.CustomButtonField;
import com.profiloc.ui.custom.CustomLabelField;
import com.profiloc.util.LocationHandler;

public class MainMenuScreen extends SplashScreen implements FieldChangeListener{

	private CustomButtonField byLocationButton;
	private VerticalFieldManager verticalMenu;
	private CustomLabelField titleBar;
	private CustomButtonField showMyProfiles;
	
	private Bitmap icon = Bitmap.getBitmapResource("rsz_3icon.png");
	
	public MainMenuScreen() {
		
		super(Bitmap.getBitmapResource("splash.png"),5);
		
		titleBar = new CustomLabelField("  Profiloc - Main Menu",Color.WHITE, 0x000000, icon, Field.USE_ALL_WIDTH);

		setTitle(titleBar);
		/*
		 * create manager to hold menus vertically
		 */
		HorizontalFieldManager menuHor1 = new HorizontalFieldManager(Field.FIELD_HCENTER);
		byLocationButton  = new CustomButtonField("Profile Using Location",0xFFCC00);
		byLocationButton.setChangeListener(this);
		menuHor1.add(byLocationButton);
		
		
		HorizontalFieldManager menuHor3 = new HorizontalFieldManager(Field.FIELD_HCENTER);
		showMyProfiles =  new CustomButtonField("Show My Profiles", 0xFFCC00);
		showMyProfiles.setChangeListener(this);
		menuHor3.add(showMyProfiles);
		
		verticalMenu = new VerticalFieldManager(Field.FIELD_HCENTER);
		verticalMenu.add(menuHor1);
		verticalMenu.add(menuHor3);

		add(verticalMenu);
	}
	
	protected boolean onSavePrompt() {
		return true;
	}

	public void fieldChanged(Field field, int context) {
		// TODO Auto-generated method stub
		if(field == byLocationButton){
			
			GpsLocationScreen locationScreen = new GpsLocationScreen(this);
			LocationHandler handler = new LocationHandler(locationScreen,false,-1,-1);
			handler.start();
			UiApplication.getUiApplication().pushScreen(locationScreen);

		}
		
		if(field == showMyProfiles){
			
			UiApplication.getUiApplication().pushScreen(new ShowProfilesScreen(this));
		}	
	}
}
 